/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-08 21:32:24
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-18 12:33:50
 * @FilePath: \vue3_admin_template\project\src\api\acl\user\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//用户管理模块接口
import request from '@/utils/request'
import type {
  User,
  UserResponseData,
  AllRoleResponseData,
  SetRoleData,
} from '@/api/acl/user/type'

enum API {
  //获取全部已有的账号信息
  ALLUSER_URL = '/admin/acl/user/', // {page}/{limit}
  //添加一个新的用户
  ADDUSER_URL = '/admin/acl/user/save',
  //更新已有用户信息
  UPDATEUSER_URL = '/admin/acl/user/update',
  //获取全部职位,当前账号拥有的职位接口
  ALLROLEURL = '/admin/acl/user/toAssign/',
  //分配角色接口
  SETROLE_URL = '/admin/acl/user/doAssignRole',
  //删除某一个账号
  DELETEUSER_URL = '/admin/acl/user/remove/', // userId
  //批量删除接口
  DELETEALLUSER_URL = '/admin/acl/user/batchRemove',
}

//获取全部已有的账号信息方法
export const reqAllUserInfo = (
  pageNo: number,
  limit: number,
  keyWord: string,
) =>
  request.get<any, UserResponseData>(
    API.ALLUSER_URL + `${pageNo}/${limit}/?username=${keyWord}`,
  )

//添加用户于更新已有用户方法
export const reqAddOrUpdateUser = (data: User) => {
  if (data.id) {
    //更新
    return request.put<any, any>(API.UPDATEUSER_URL, data)
  } else {
    //添加
    return request.post<any, any>(API.ADDUSER_URL, data)
  }
}
//获取全部职位以及包含当前用户的已有的职位
export const reqAllRole = (userId: number) =>
  request.get<any, AllRoleResponseData>(API.ALLROLEURL + userId)
//分配职位请求方法
export const reqDoAssignRole = (data: SetRoleData) =>
  request.post<any, any>(API.SETROLE_URL, data)
//删除某一个账号
export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + `${userId}`)
//批量删除
export const reqRemoveAll = (ids: number[]) =>
  request.delete<any, any>(API.DELETEALLUSER_URL, { data: ids })
